
/*Replication file for:  "Immigration and Support for Social Policy. 
An Experimental Comparison of Universal and Means-Tested Programs"
Submitted to: Political Science Research and Methods
*/

*Data
cd "C:\Users\Usuari\Dropbox\immigration and welfare\PSRM\Analysis\Replication"
log using "replication_munoz_pardos_PSRM.log", replace
use "replication_munoz_pardos_PSRM.dta", clear

*------------------------------------------------------------*
*----------Data preparation----------------------------------*
*------------------------------------------------------------*

*Generate treatment variables
gen treatment=.
replace treatment=1 if SJ1a_Universal_ImigrantsMentione!=9
replace treatment=2 if SJ1b_Universal_ImigrantsNotMenti!=9
replace treatment=3 if SJ1c_MeansTested_ImigrantsMentio!=9
replace treatment=4 if SJ1d_MeansTested_ImigrantsNotMen!=9
label define treatment 1"Univ Immi" 2"Universal NI" 3"MT Immi" 4"MT NI"
label values treatment treatment
tab treat

gen universal=0
replace universal=1 if treatment<3
label define universal 0"Means-Tested" 1"Universal"
label values universal universal
tab universal

gen immi=0
replace immi=1 if treatment==1
replace immi=1 if treatment==3
label define immi 0"No immigration priming" 1"Immigration priming"
label values immi immi
tab immi

*Generate dependent variable
gen dv= SJ1b_Universal_ImigrantsNotMenti
replace dv= SJ1c_MeansTested_ImigrantsMentio if dv==9
replace dv= SJ1d_MeansTested_ImigrantsNotMen if dv==9
replace dv= SJ1a_Universal_ImigrantsMentione if dv==9
recode dv (5=.a)
label values dv SJ1d_MeansTested_ImigrantsNotMen
tab dv

*Generate moderators
gen culture= SJ4 if SJ4<12
replace culture=culture-1
gen prejudice=-culture+10 /*from less to more prejudice*/

gen deserving1=SJ5a-1 if SJ5a<12
tab deserving1

*------------------------------------------------------------*
*----------Analysis------------------------------------------*
*------------------------------------------------------------*

*Table 3. Results of the experiment (column percentages).
tab dv treat, col nofreq
tab dv immi, col nofreq

*Proportion tests (table 3)
tab dv, gen(dv)

foreach var of varlist dv1-dv4 {
prtest `var', by(immi)
}

foreach var of varlist dv1-dv4 {
prtest `var' if univ==1, by(immi)
}

foreach var of varlist dv1-dv4 {
prtest `var' if univ==0, by(immi)
}

*Figure 1
reg dv immi##c.prej
margins, dydx(immi) over(prej)
marginsplot, yline(0) recast(line) recastci(rline) title("Cultural prejudice") xtitle("Cultural prejudice") ytitle("Predicted change in support") name(fig1a)

reg dv immi##c.deserving1
margins, dydx(immi) over(deserving1)
marginsplot, yline(0) recast(line) recastci(rline) title("Deservingness Beliefs") xtitle("Deservingness") ytitle("Predicted change in support") name(fig1b)
gr combine fig1a fig1b, title("Effect of immigration treatment, by prejudice and deservingness")
graph save fig1, replace
graph export fig1.pdf, replace

*Figure 2
reg dv immi##universal
margins, over(immi universal)
marginsplot, title("Effect of immigration, by type of policy") ytitle("Predicted support") xtitle("")
graph save fig2, replace
graph export fig2.pdf, replace

*Figure 3a
reg dv c.deserving1##universal if immi==1
est store Deservingness
margins, dydx(deserving1) at(universal=(0 1))
marginsplot, recast(scatter) recastci(rspike) title("Effects of deservingness beliefs, under immigration treatment") ///
	subtitle("Average Marginal Effects with 95% CIs") xtitle("") ytitle("Effect on support for child benefits") 
graph save fig3a, replace
graph export fig3a.pdf, replace

*Figure 3b
reg dv c.prej##universal if immi==1
est store Prejudice 
margins, dydx(prej) at(universal=(0 1))
marginsplot, recast(scatter) recastci(rspike) title("Effects of Cultural prejudice, under immigration treatment") ///
	subtitle("Average Marginal Effects with 95% CIs") xtitle("") ytitle("Effect on support for child benefits") 
graph save fig3b, replace
graph export fig3b.pdf, replace

*Figure 4a
reg dv immi##c.education##univ
est store Education
margins, over(immi) at(education=(1 2 3 4) univ=(0 1) )
marginsplot, by(universal) recastci(rspike) byopt(title("Support for child benefits, by treatment and education")) xtitle("") ytitle("Predicted Support")
graph save fig4a, replace
graph export fig4a.pdf, replace

*Figure 4b
reg dv immi##c.socgrade##univ
est store SocialGrade
margins, over(immi) at(socgrade=(1 2 3 4) univ=(0 1))
marginsplot, by(universal) recastci(rspike) byopt(title("Support for child benefits, by treatment and Social Grade")) xtitle("") ytitle("Predicted Support")
graph save fig4b, replace
graph export fig4b.pdf, replace

*Figure 5a
reg dv immi##c.deserving1##c.education 
est store Education_des
margins, dydx(deserving1) at(education=(1 2 3 4) immi=(0 1))
marginsplot, recastci(rspike) title("Effect of deservingness beliefs, by treatment and Education") ytitle("Effects on Support for Child Benefits") yline(0)
graph save fig5a, replace
graph export fig5a.pdf, replace

*Figure 5b
reg dv immi##c.deserving1##c.socgrade
est store SocialGrade_des 
margins, dydx(deserving1) at(socgrade=(1 2 3 4) immi=(0 1))
marginsplot, recastci(rspike) title("Effect of deservingness beliefs, by treatment and Social Grade") ytitle("Effects on Support for Child Benefits") yline(0)
graph save fig5b, replace
graph export fig5b.pdf, replace

*Figure 6a
reg dv immi##c.prej##c.education
est store Education_prej
margins, dydx(prej) at(education=(1 2 3 4) immi=(0 1))
marginsplot, recastci(rspike) ///
	title("Effect of Prejudice, by treatment and Education") ///
	subtitle("Average Marginal Effects and 95% CI") yline(0)
graph save fig6a, replace
graph export fig6a.pdf, replace

*Figure 6b
reg dv immi##c.prej##c.socgrade 
est store SocialGrade_prej
margins, dydx(prej) at(socgrade=(1 2 3 4) immi=(0 1))
marginsplot, recastci(rspike) ///
	title("Effect of Prejudice, by treatment and Social Grade") ///
	subtitle("Average Marginal Effects and 95% CI") yline(0)
graph save fig6b, replace
graph export fig6b.pdf, replace
	

*------------------------------------------------------------*
*----------Appendix------------------------------------------*
*------------------------------------------------------------*


*Table A1: Effects of deservingness beliefs and prejudice, under immigration treatment by policy condition (3a & 3b)
esttab Deservingness Prejudice using models_appendix.rtf, cell(b(star fmt (%9.2f)) se(par)) ///
 stats(N r2, fmt(%9.0g %9.3f) labels("Observations" "R2")) /// 
	starlevels(* 0.1 ** 0.05 *** 0.01) legend label varlabels(_cons Constant) noomitted nobaselevels ///
	 title("Table A1: Effects of deservingness beliefs and prejudice, under immigration treatment by policy condition (3a & 3b)") mtitles replace

*Table A2: Support for child benefits, by treatment and education/Social grade (4a&b)
esttab Education SocialGrade using models_appendix.rtf, cell(b(star fmt (%9.2f)) se(par)) ///
 stats(N r2, fmt(%9.0g %9.3f) labels("Observations" "R2")) /// 
	starlevels(* 0.1 ** 0.05 *** 0.01) legend label varlabels(_cons Constant) noomitted nobaselevels ///
	 title("Table A2: Support for child benefits, by treatment and Education/Social grade (Figures 4a&b)") mtitles append

*Table A3: Effect of Prejudice, by treatment and Education/Social Grade (6a&b)
esttab Education_des SocialGrade_des Education_prej SocialGrade_prej using models_appendix.rtf, cell(b(star fmt (%9.2f)) se(par)) ///
 stats(N r2, fmt(%9.0g %9.3f) labels("Observations" "R2")) /// 
	starlevels(* 0.1 ** 0.05 *** 0.01) legend label varlabels(_cons Constant) noomitted nobaselevels ///
	 title("Table A3: Effect of Other-regarding considerations, by treatment and Education/Social Grade (Figures 4&5)") mtitles append

*Appendix2: ologit

*Table A2.2.1: Effects of deservingness beliefs and Prejudice, under immigration treatment by policy condition 
olog dv c.deserving1##universal if immi==1
est store Deservingness_olog

olog dv c.prej##universal if immi==1
est store Prejudice_olog 

esttab Deservingness_olog Prejudice_olog using models_appendix.rtf, cell(b(star fmt (%9.2f)) se(par)) ///
 stats(N r2_p, fmt(%9.0g %9.3f) labels("Observations" "Pseudo-R2")) /// 
	starlevels(* 0.1 ** 0.05 *** 0.01) legend label varlabels(_cons Constant) noomitted nobaselevels ///
	 title("Table A2.2.1: Effects of deservingness beliefs and prejudice, under immigration treatment by policy condition (3a & 3b)") mtitles append

*Table A2.2: Support for child benefits, by treatment and education/Social grade (4a&b)
olog dv immi##c.education##univ
est store Education_olog

olog dv immi##c.socgrade##univ
est store SocialGrade_olog

esttab Education_olog SocialGrade_olog using models_appendix.rtf, cell(b(star fmt (%9.2f)) se(par)) ///
 stats(N r2_p, fmt(%9.0g %9.3f) labels("Observations" "Pseudo-R2")) /// 
	starlevels(* 0.1 ** 0.05 *** 0.01) legend label varlabels(_cons Constant) noomitted nobaselevels ///
	 title("Table A2.2: Support for child benefits, by treatment and Education/Social grade (Figures 4a&b)") mtitles append

*Table A2.3: Effect of Prejudice, by treatment and Education/Social Grade (6a&b)

olog dv immi##c.deserving1##c.education 
est store Education_des_olog

olog dv immi##c.deserving1##c.socgrade
est store SocialGrade_des_olog 

olog dv immi##c.prej##c.education
est store Education_prej_olog

olog dv immi##c.prej##c.socgrade 
est store SocialGrade_prej_olog
	
esttab Education_des_olog SocialGrade_des_olog Education_prej_olog SocialGrade_prej_olog using models_appendix.rtf, cell(b(star fmt (%9.2f)) se(par)) ///
 stats(N r2_p, fmt(%9.0g %9.3f) labels("Observations" "Pseudo-R2")) /// 
	starlevels(* 0.1 ** 0.05 *** 0.01) legend label varlabels(_cons Constant) noomitted nobaselevels ///
	 title("Table A2.3: Effect of Other-reggarding considerations, by treatment and Education/Social Grade (Figures 4&5)") mtitles append

log close
clear
